﻿using System;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace YRevitJig
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
	public class Jig3PtArc : IExternalCommand
	{
		public Result Execute(ExternalCommandData cmdData, ref string message, ElementSet elements)
		{
			UIDocument activeUIDocument = cmdData.Application.ActiveUIDocument;
			ViewAssist.ViewValidating(activeUIDocument.Document, activeUIDocument.ActiveView);
			XArc3PtJig xarc3PtJig = new XArc3PtJig(activeUIDocument);
			XYZ xyz = xarc3PtJig.PickStartPoint("请确定圆弧起点：");
			Result result;
			if (xyz == null)
			{
				xarc3PtJig.Dispose();
				result = Autodesk.Revit.UI.Result.Succeeded;
			}
			else
			{
				XYZ xyz2 = xarc3PtJig.PickEndPoint(xyz, "请确定圆弧终点：");
				if (xyz2 == null)
				{
					xarc3PtJig.Dispose();
					result = Autodesk.Revit.UI.Result.Succeeded;
				}
				else
				{
					XYZ xyz3 = xarc3PtJig.PickOnCurvePoint(xyz, xyz2, "请确定圆弧上的点：");
					if (xyz3 == null)
					{
						xarc3PtJig.Dispose();
						result = Autodesk.Revit.UI.Result.Succeeded;
					}
					else
					{
						Transaction transaction = new Transaction(activeUIDocument.Document);
						transaction.Start("CreateCurve");
						Arc arc = Arc.Create(xyz, xyz2, xyz3);
						activeUIDocument.Document.Create.NewDetailCurve(activeUIDocument.ActiveView, arc);
						transaction.Commit();
						xarc3PtJig.Dispose();
						result = Autodesk.Revit.UI.Result.Succeeded;
					}
				}
			}
			return result;
		}
	}
}
